function getQueryString(name) {
  var reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)', 'i');
  var r = window.location.search.substr(1).match(reg);
  if (r != null) {
    return unescape(r[2]);
  }
  return null;
}
layui.use(['table','form'], function(){
  var table = layui.table;
  var form = layui.form;
  var delurl = "/general/erp5/public/tripapi/plan/Delete";
  //方法级渲染
  table.render({
    elem: '#apply_list'
    ,url: '/general/erp5/public/tripapi/plan/GetitemByAjax'
    ,request: {
      page: 'page',   // 页码的参数名称，默认：page
      limit: 'limit'   // 每页数据量的参数名，默认：limit
    }
    ,response: {
        statusName: 'status'
        ,statusCode: 200
        ,msgName: 'msg'
        ,countName: 'count'
        ,dataName: 'data'
      }
    ,cols: [[
       {checkbox: true, fixed: true}
      ,{field:'id', title: 'ID',width:70,align:'center'}
      ,{field:'contract_name', title: '项目合同名称',width: 150,align:'center'}
      ,{field:'apply_num', title: '出差申请单号',width: 150,align:'center'}
      ,{field:'write_time', title: '填写日期',width: 150,align:'center'}
      ,{field:'contract_num', title: '合同编号',width: 150,align:'center'}
      ,{field:'traveler', title: '出差人员名单',width: 150,align:'center'}
      ,{field:'department', title: '出差费用归属公司/部门', width: 150,align:'center'}
      ,{field:'apply_user', title: '申请人',width: 150,align:'center'}
      ,{field:'charge_user', title: '出差负责人',width: 150,align:'center'}
      ,{field:'travel_time', title: '出差时间',width: 150,align:'center'}
      ,{field:'travel_place', title: '出差地点',width: 200,align:'center'}
      ,{field:'user_num', title: '出差总人数',width: 200,align:'center'}
      ,{field:'travel_day', title: '出差总天数',width: 200,align:'center'}
      ,{field:'reason', title: '出差事由',width: 100,align:'center'}
      ,{field:'contacter', title: '接洽人',width: 100,align:'center'}
      ,{field:'tel', title: '联系电话',width: 100,align:'center'}
      ,{field:'target', title: '出差目的',width: 100,align:'center'}
      ,{field:'business_money', title: '业务费预算小计',width: 200,align:'center'}
      ,{field:'budget_money', title: '费用预算合计',width: 200,align:'center'}
      ,{field:'cost_bear', title: '费用承担',width: 200,align:'center'}
      ,{field:'depart_opinion', title: '部门意见',width: 200,align:'center'}
      ,{field:'politic_opinion', title: '行政意见',width: 200,align:'center'}
      ,{field:'finance_opinion', title: '财务意见',width: 200,align:'center'}
      ,{field:'finance_total', title: '财务建议支出金额',width: 200,align:'center'}
      ,{field:'manager_opinion', title: '总经理意见',width: 200,align:'center'}
      ,{field:'remark', title: '备注',width: 200,align:'center'}
      ,{field:'creator', title: '创建人',width: 100,align:'center'}
      ,{field:'', title: '操作',width: 200,align:'center', toolbar:'#tab1Bar'}
    ]]
    ,id: 'testReload'
    ,page: true
    ,toolbar:"#tab2Bar"
    ,text: { none: '暂无相关数据' }
  });
  table.on('tool(user)', function (obj) {
    switch(obj.event){
      case 'show':
        location.replace("/general/erp5/public/tripapi/plan/showitem?id=" + obj.data.id);
        break;
    }
  })
  table.on('toolbar(user)', function (obj) {
    switch(obj.event){
      case 'show':
        location.replace("/general/erp5/public/tripapi/plan/add");
        break;
    }

  })
  form.on('submit(demo1)', function(data){
        $.ajax({
            type: "POST",
            url: "/general/erp5/public/",
            data: data.field,
            traditional: true,
            dataType:"json",
            success: function(returnData){

            }
        })
        return false;
    });
  $("#reloadBtn").click(function (ev) {
    console.info("reload");
    var department = $("#department").val();
    var approve_people = $("#approve_people").val();
    var travel_people = $("#travel_people").val();
    table.reload('testReload', {
      url: '/general/erp5/public/tripapi/plan/SearchResult'
      , where: {
        department: department,
        approve_people: approve_people,
        travel_people: travel_people
      }

    });

  })

  $('.apply_table .layui-btn').on('click', function(){
    var type = $(this).data('type');
    active[type] ? active[type].call(this) : '';
  });
});